{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-11-28T06:57:50.500240Z",
     "start_time": "2024-11-28T06:57:25.375696Z"
    }
   },
   "source": [
    "import os.path\n",
    "\n",
    "from PIL import Image\n",
    "import numpy as np\n",
    "import h5py\n",
    "\n",
    "data_path = 'E:\\\\DeepLearningCopies\\\\2023\\\\RIDCP\\\\datasets\\\\I-HAZE-test.h5'\n",
    "dir_path = \"E:\\\\DeepLearningCopies\\\\2023\\\\RIDCP\\\\datasets\\\\I-HAZE\"\n",
    "if not os.path.exists(dir_path):\n",
    "    os.makedirs(dir_path + '\\\\clean')\n",
    "    os.makedirs(dir_path + '\\\\hazy')\n",
    "h5f = h5py.File(data_path, 'r')\n",
    "keys = list(h5f.keys())\n",
    "length = len(keys)\n",
    "for i in range(length):\n",
    "    img_data = np.array(h5f[keys[i]])\n",
    "    gt = (np.transpose(img_data[0], (1, 2, 0)) * 255).astype(np.uint8)\n",
    "    lq = (np.transpose(img_data[1], (1, 2, 0)) * 255).astype(np.uint8)\n",
    "    Image.fromarray(gt).save(dir_path + '\\\\clean\\\\'+ str(i + 1).zfill(2) + '_GT.png')\n",
    "    Image.fromarray(lq).save(dir_path + '\\\\hazy\\\\'+ str(i + 1).zfill(2) + '_hazy.png')\n",
    "h5f.close()"
   ],
   "outputs": [],
   "execution_count": 13
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "907fa7200ceee732"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
